🐳 Fix docker compose runtime blockers on clean clone - #4
Merged
Conversation
- Drop obsolete compose version key; load backend/.env via env_file and stop shadowing ANTHROPIC_API_KEY/OPENAI_API_KEY with empty host vars, which tripped the must_not_be_empty validator before the app started - Seed MongoDB automatically from FastAPI lifespan via idempotent seed_if_empty(), so first boot always has sample data - Replace the superuser get-then-create sequence with an atomic $setOnInsert upsert, fixing a DuplicateKeyError on repeated/concurrent boots - Add a proper .dockerignore (.git, node_modules, chroma_db, etc.) and fix Dockerfile.backend PATH so pip --target console scripts (uvicorn) are actually runnable in the final image - Disable LangSmith tracing by default in .env.example - Update README quick start to reflect automatic seeding - Migrate remaining Pydantic .dict() calls to .model_dump()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
docker compose updid not work on a clean clone. Seven separate blockers, fixed together since they compound (fixing one just exposes the next):env_filein compose —backendservice had noenv_file, and theenvironment:block substituted${ANTHROPIC_API_KEY}/${OPENAI_API_KEY}from the (unset) host shell as empty strings, shadowingbackend/.envand tripping themust_not_be_emptyvalidator inconfig.pybefore the app could start.backend/data/seed.pywas a standalone script; a cleandocker compose uplanded on an empty database. Refactored into an idempotentseed_if_empty(db)(returns early ifsuppliersis non-empty) and called it from the FastAPI lifespan.get_user_by_email→create_usersequence raisedDuplicateKeyErroron repeated or concurrent boots against the unique{email:1}index. Replaced with a single atomicupdate_one({...}, {"$setOnInsert": {...}}, upsert=True).LANGCHAIN_TRACING_V2=falseinbackend/.env.example(wastruewith no API key set, which is a broken default).python backend/data/seed.py(wrong path,ModuleNotFoundError). Now states sample data is seeded automatically on first startup, with the correct manual re-seed command (cd backend && PYTHONPATH=. python data/seed.py).Dockerfile.backendPATH fix —pip install --targetplaces console scripts (includinguvicorn) undersite-packages/bin, which was never added toPATHin the final image. The backend container failed to start on every clean build withexec: "uvicorn": executable file not found in $PATH. Found this while verifying the other five fixes end-to-end — without itdocker compose upstill didn't work..dockerignore— none existed, so every build sent the full repo (.git,node_modules,chroma_db, etc.) as build context. Confirmed 104MB and still climbing after 11+ minutes on a realnpm install'd checkout, never finishing.Also migrated the remaining Pydantic v2
.dict()calls inseed.pyto.model_dump().Verification
docker compose config | grep -i anthropic— key resolves frombackend/.env, never appears emptydocker compose up --build— all three containers (backend, frontend, mongo) start cleanlycurl localhost:8000/suppliers(authenticated) — 12 suppliers, 16 bids seededdocker compose restart backend— clean second boot: logssuperuser_exists, no seed re-run, no crashcd backend && pytest— 160 passed.dockerignorefix → ~6 seconds afterTest plan
docker compose up --buildsucceeds on a clean clone/suppliersreturns 12 records after logindocker compose restart backend) does not crash or re-seedpytest— 160/160 passing